/* jaDTi package - v0.6.1 */
package grex.DT.Test;

import grex.Data.ArffTableModel;
import grex.BNFException;
import grex.Environment;
import grex.Options;
import grex.DT.tree.DecisionTreeBuilder;
import grex.genes.GeneException;

import java.io.IOException;
import java.io.Serializable;


/*
 * A short example program of the jaDTi library.
 */
public class Classify implements Serializable {

    static public void main(String[] args) throws IOException, BNFException, GeneException {

        int nrFolds = 10;
        double totAcc = 0;
        

        ArffTableModel arff = new ArffTableModel("iris.arff", nrFolds, 1);
        Options ops = new Options();
        ops.setBNF_FILE("if.txt");
        ops.setFITNESS_FUNCTION("ACCFitness");
        ops.setNR_OF_INPUT_COLUMNS(arff.getNrOfCategorialColumns() + arff.getNrOfContinousColumns());
        ops.setTestFOLD("F2");
        Environment env = new Environment(arff, ops);
        env.setData(arff);
        DecisionTreeBuilder builder = new DecisionTreeBuilder(env,false);
        builder.buildDecisionTree();
        System.out.println(builder.getTree().toString());
        System.out.println("\n\nGP:");
        System.out.println(builder.getTreeAsGP().getFormatedTree());
        /*builder.buildAscendingBootStrapTrees(10,0.1, 0.001);
        ArrayList<GP> trees = builder.getBootStrapTreesSsArrayList();
        for(GP gp:trees)
            System.out.println("GP Size:" + gp.getLength());*/
         /*builder.buildBootStrapTrees(5);
        ArrayList<GP> arl = builder.getBootStrapTreesSsArrayList();
        System.out.println(arl.get(0).toString());
        System.out.println("");
        System.out.println("");
        System.out.println(arl.get(1).toString());//*/
        //builder.buildDecisionTree();
       /* builder.buildRandomForrest(10);
        GP[] gps = builder.getForrestAsGPs();
        GPEnsemble ens = new GPEnsemble(env,50);
        StatisticsACC sacc = new StatisticsACC();
        System.out.println("Ens TrainACC:" + sacc.calcACC(ens, ens.getPcTrain()));
        System.out.println("Ens TestACC:" + sacc.calcACC(ens, ens.getPcTest()));

        System.out.println("ForrestBuilder TRain ACC: "+ builder.calcForrestAcc(false));
        System.out.println("ForrestBuilder test ACC: "+ builder.calcForrestAcc(true));
        for(GP gp:ens.getMembers()){
            System.out.println("");
            System.out.println("GP TrainACC:" + sacc.calcACC(gp, ens.getPcTrain()));
            System.out.println("GP TestACC:" + sacc.calcACC(gp, ens.getPcTest()));
        }*/
        

        //double avgAcc=0,avgTreeAcc=0;
       
       /* for(int i = 1; i <= nrFolds;i++){
            env.getOptions().setTestFOLD("F"+i);
        /*    builder.buildDecisionTree();
            double treeAcc =  builder.calcAcc(true);
            double treeTrainAcc = builder.calcAcc(false);
            avgTreeAcc +=treeAcc/nrFolds;*/
            /*GP gp= builder.getTreeAsGP();
            System.out.println(gp.getGPTestPrediction());
            System.out.println("GP   Train F"+i+"\tTreeAcc:" + sacc.calcACC(gp,gp.getPcTrain())+"Test F"+"\tTreeAcc:" + sacc.calcACC(gp, gp.getPcTest()));
            System.out.println("Tree Train F"+i+"\tTreeAcc:" + treeTrainAcc+"Test F"+"\tTreeAcc:" + treeAcc);//*/
         /*   builder.buildRandomForrest(100);
            double acc = builder.calcForrestAcc(true);
            double trainAcc = builder.calcForrestAcc(false);
         //   System.out.println("Train F"+i+" \tForestAcc:" +trainAcc+ "\tTreeAcc:" + treeTrainAcc+"Test F"+i+" \tForestAcc:" +acc+ "\tTreeAcc:" + treeAcc);
       /*     System.out.println("Train F"+i+" \tForestTrainAcc:" +trainAcc+"Test F"+i+" \tForestTestAcc:" +acc);
            avgAcc+=acc/nrFolds;//*/
     //   }
     /*   System.out.println("GP-----------------\n"+gp.getFormatedTree());
        System.out.println("Tree----------------\n"+builder.getTree());//*/
        //System.out.println("\nAvgAcc:" + avgAcc + " \t acgTreeAcc" + avgTreeAcc);


    }


    


}
